﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SymulatorEthernetWPF.SimObjects.Devices;

namespace SymulatorEthernetWPF.SimObjects
{
    class SwitchTable
    {
        private List<SwitchTableItem> switchTableItemList = new List<SwitchTableItem>();

        internal SwitchTable()
        {
        }

        internal void addMAC(NetworkInterface networkInterface, MacAdress macAdress)
        {
            foreach (SwitchTableItem it in switchTableItemList)
            {
                if(it.macAdress.Equals(macAdress))
                {
                    it.networkInterface = networkInterface;
                    return;
                }
            }
            networkInterface.Owner.logList.Add("[" + Simulation.tickCount + "](" + networkInterface.Name + ") Tablica skojarzeń, port " + networkInterface.Name+", adres "+macAdress.Adress);
            switchTableItemList.Add(new SwitchTableItem() { macAdress = new MacAdress(macAdress.Adress), networkInterface = networkInterface });
        }

        internal NetworkInterface findInterface(MacAdress macAdress)
        {
            foreach (SwitchTableItem it in switchTableItemList)
            {
                if (it.macAdress.Equals(macAdress))
                {
                    return it.networkInterface;
                }
            }
            return null;
        }
    }
}
